﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MFD.SharePoint.SPBackup
{
    public class Logger
    {
        
        
        private List<Message> messages = new List<Message>();

        public Logger()
        {
        }
        
        public void Log(Exception ex)
        {
            messages.Add(new Message(MessageType.Error,ex.ToString()));
            Console.WriteLine(ex);
        }
        
        
        public void Log(string msgText)
        {
            messages.Add(new Message(MessageType.Info,msgText));
            Console.WriteLine(msgText);
        }


        bool IsError(Message msg)
        {
            return msg.MsgType == MessageType.Error;
        }

        public Message GetLastError()
        {
            return  messages.FindLast(IsError);
            
        }
         
        public void ForEachMessage(Action<Message> action)
        {
            messages.ForEach(action);
        }

        public int GetErrorcount()
        {
            List<Message> l = messages.FindAll(IsError);
            return l.Count;
        }
    }
}
